package org.capybara.coffeehouse.device;

import org.apache.log4j.Logger;
import org.capybara.coffeehouse.insteon.InsteonAddress;
import org.capybara.coffeehouse.insteon.InsteonMessage;
import org.capybara.coffeehouse.insteon.PlmDriver;

public class Insteon2457D2 extends Device implements InsteonDevice, LightDimmer {

	private InsteonAddress address;
	private String name;
	private final Logger log = Logger.getLogger(Insteon2457D2.class);
	private PlmDriver plm;

	public Insteon2457D2(String name, InsteonAddress address) {
		this.name = name;
		this.address = address;
	}
	
	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void handleMessage(InsteonMessage m) {
		log.debug(name+" got message: "+m);
	}

	@Override
	public InsteonAddress getAddress() {
		return address;
	}

	@Override
	public void setBrightness(double level, long fadeTimeMillis) {
		log.info("setting brightness to "+level+" in "+fadeTimeMillis+" millis");
		if (plm != null) {
			if (level > 0) {
				InsteonMessage message = new InsteonMessage(address, 0x11, 0xFF);
				plm.sendInsteonMessage(message);
			} else {
				InsteonMessage message = new InsteonMessage(address, 0x13, 0xFF);
				plm.sendInsteonMessage(message);
			}
		}
	}

	@Override
	public double getBrightness() {
		// TODO Auto-generated method stub
		return 0;
	}

	public PlmDriver getPlm() {
		return plm;
	}

	public void setPlm(PlmDriver plm) {
		this.plm = plm;
	}

}
